package cn.git.shiro.exception;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 全局异常处理，现在只标记权限校验失败处理
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2024-03-27
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * UnauthorizedException 权限验证失败处理器
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(UnauthorizedException.class)
    public Result handleUnauthorizedException(UnauthorizedException e) {
        Result result = new Result();
        result.setCode("401");
        result.setData("擦擦");
        result.setMessage("没有权限");
        return result;
    }



    /** 
     * @description: 异常响应返回信息
     * @program: bank-credit-sy
     * @author: lixuchun
     * @create: 2024-03-27
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Result {
        /**
         * 响应信息
         */
        private String message;

        /**
         * 响应码
         */
        private String code;

        /**
         * 响应数据
         */
        private Object data;
    }

}
